package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Inventory;
import cn.gson.springboot.model.service.InventoryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class InventoryController {
    @Autowired
    InventoryService invService;

    @RequestMapping("/inv-list")
    @ResponseBody
    public Map<String,Object> invList(Integer page,Integer size,Integer warId,String content){
        Page<Object> objects = PageHelper.startPage(page, size);
        List<Inventory> inv = invService.selectInventory(warId,content);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",inv);
        map.put("total",objects.getTotal());
        return map;
    }
    @RequestMapping("/inv-all-list")
    @ResponseBody
    public List<Inventory> invAllList(Integer warId){
        List<Inventory> inv = invService.selectInventory(warId,null);
        return inv;
    }

    @RequestMapping("/compute-inventory-count")
    @ResponseBody
    public List<Map<String, Object>>  computeInventoryCount(){
        List<Map<String, Object>> maps = invService.computeInventoryCount();
        return maps;
    }

    @RequestMapping("/compute-inventory-sort")
    @ResponseBody
    public List<Map<String, Object>>  computeInventorySort(){
        List<Map<String, Object>> maps = invService.computeInventorySort();
        return maps;
    }

    @RequestMapping("/compute-inventory-flow-count")
    @ResponseBody
    public List<Map<String, Object>>  computeInventoryFlowCount(){
        List<Map<String, Object>> maps = invService.computeInventoryFlowCount();
        return maps;
    }

    @RequestMapping("/compute-inventory-flow-ope")
    @ResponseBody
    public List<Map<String, Object>>  computeInventoryFlowOperation(){
        List<Map<String, Object>> maps = invService.computeInventoryFlowOperation();
        return maps;
    }

    @RequestMapping("/compute-inventory-flow-into-month")
    @ResponseBody
    public List<Map<String, Object>>  computeInventoryFlowIntoMonth(){
        List<Map<String, Object>> maps = invService.computeInventoryFlowIntoMonth();
        return maps;
    }

    @PostMapping("/save-inventory")
    @ResponseBody
    public void saveInventory(@RequestBody Inventory inventory){
        invService.saveInventory(inventory);
    }

    @PostMapping("/delete-inventory")
    @ResponseBody
    public void deleteInventory(@RequestParam(value = "invId") Integer invId){
        invService.deleteInventory(invId);
    }
}
